home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
DELPHI32
/
GRAPHICS
/
IMGLIB95
/
UICONLB.PA_
/
UICONLB.PA
Wrap
Text File
|
1996-03-31
|
10KB
|
344 lines
{
Written by Jan Dekkers and Kevin Adams (c) 1995, 1996. If you are a non
registered client, you may use or alter this demo only for evaluation
purposes.
Copyright by SkyLine Tools. All rights reserved.
Part of Imagelib VCL/DLL Library.
}
unit UIconLB;
{Includes settings to compile in either 16 or 32 bit}
{$I DEFILIB.INC}
interface
uses
{$IFDEF DEL32}
Windows,
{$ELSE}
WinTypes,
WinProcs,
{$ENDIF}
DLL95V1, {ImageLib Dll interface and misc. functions}
Classes,
Graphics,
Forms,
Controls,
Buttons,
StdCtrls,
DBTables,
DB,
SysUtils,
ExtCtrls,
Mask,
DBCtrls,
Dialogs,
Tdbicon; {TDBIconEditor, TDBIconListBox, TDBIconComboBox VCL component}
{-----------------------------------------------------------------------}
type
TIconListBoxDlg = class(TForm)
CancelBtn: TBitBtn;
SrcLabel: TLabel;
DstLabel: TLabel;
IncludeBtn: TSpeedButton;
IncAllBtn: TSpeedButton;
ExcludeBtn: TSpeedButton;
ExAllBtn: TSpeedButton;
Table1: TTable;
BitBtn2: TBitBtn;
SrcList: TDBIconListBox;
CheckBox1: TCheckBox;
DBIconComboBox1: TDBIconComboBox;
Label1: TLabel;
DBIconEditor1: TDBIconEditor;
DstList: TDBIconListBox;
procedure IncludeBtnClick(Sender: TObject);
procedure ExcludeBtnClick(Sender: TObject);
procedure IncAllBtnClick(Sender: TObject);
procedure ExcAllBtnClick(Sender: TObject);
procedure MoveSelected(List: TCustomListBox; Items: TStrings);
procedure SetItem(List: TListBox; Index: Integer);
procedure SetItem2(List: TListBox; Index: Integer);
function GetFirstSelection(List: TCustomListBox): Integer;
procedure SetButtons;
procedure FormCreate(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure DstListDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure SrcListMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SrcListDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure DstListMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DstListDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure SrcListDragDrop(Sender, Source: TObject; X, Y: Integer);
private
Procedure AddListBoxItems;
public
{ Public declarations }
end;
var
IconListBoxDlg : TIconListBoxDlg;
implementation
{$R *.DFM}
procedure TIconListBoxDlg.IncludeBtnClick(Sender: TObject);
var
Index: Integer;
begin
Index := GetFirstSelection(SrcList);
MoveSelected(SrcList, DstList.Items);
SetItem(SrcList, Index);
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.ExcludeBtnClick(Sender: TObject);
var
Index: Integer;
begin
Index := GetFirstSelection(DstList);
MoveSelected(DstList, SrcList.Items);
SetItem(DstList, Index);
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.IncAllBtnClick(Sender: TObject);
var
I: Integer;
begin
for I := 0 to SrcList.Items.Count - 1 do begin
DstList.Items.AddObject(SrcList.Items[I], SrcList.Items.Objects[I]);
end;
SrcList.Items.Clear;
SetItem(SrcList, 0);
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.ExcAllBtnClick(Sender: TObject);
var
I: Integer;
begin
for I := 0 to DstList.Items.Count - 1 do
SrcList.Items.AddObject(DstList.Items[I], DstList.Items.Objects[I]);
DstList.Items.Clear;
SetItem(DstList, 0);
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.MoveSelected(List: TCustomListBox; Items: TStrings);
var
I: Integer;
begin
for I := List.Items.Count - 1 downto 0 do
if List.Selected[I] then
begin
Items.AddObject(List.Items[I], List.Items.Objects[I]);
List.Items.Delete(I);
end;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.SetButtons;
var
SrcEmpty, DstEmpty: Boolean;
begin
SrcEmpty := SrcList.Items.Count = 0;
DstEmpty := DstList.Items.Count = 0;
IncludeBtn.Enabled := not SrcEmpty;
IncAllBtn.Enabled := not SrcEmpty;
ExcludeBtn.Enabled := not DstEmpty;
ExAllBtn.Enabled := not DstEmpty;
end;
{-----------------------------------------------------------------------}
function TIconListBoxDlg.GetFirstSelection(List: TCustomListBox): Integer;
begin
for Result := 0 to List.Items.Count - 1 do
if List.Selected[Result] then Exit;
Result := LB_ERR;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.SetItem(List: TListBox; Index: Integer);
var
MaxIndex: Integer;
begin
with List do
begin
SetFocus;
MaxIndex := List.Items.Count - 1;
if Index = LB_ERR then Index := 0
else if Index > MaxIndex then Index := MaxIndex;
Selected[Index] := True;
end;
SetButtons;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.FormCreate(Sender: TObject);
begin
Table1.DataBaseName:=ExtractFilePath(Application.ExeName);
Table1.Active:=True;
AddListBoxItems;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.BitBtn2Click(Sender: TObject);
begin
If DBIconEditor1.Execute then
AddListBoxItems;
end;
{-----------------------------------------------------------------------}
Procedure TIconListBoxDlg.AddListBoxItems;
begin
Table1.First;
SrcList.Items.Clear;
DBIconComboBox1.Items.Clear;
While not Table1.EOF do begin
SrcList.Items.Add(Table1.FieldByName('ICONDESC').AsString);
DBIconComboBox1.Items.Add(Table1.FieldByName('ICONDESC').AsString);
Table1.Next;
end;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.SetItem2(List: TListBox; Index: Integer);
var
MaxIndex: Integer;
begin
with List do
begin
SetFocus;
MaxIndex := List.Items.Count - 1;
if Index = LB_ERR then Index := 0
else if Index > MaxIndex then Index := MaxIndex;
Selected[Index] := True;
end;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.CancelBtnClick(Sender: TObject);
begin
Close;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.CheckBox1Click(Sender: TObject);
begin
SrcList.ShowIcons:=CheckBox1.Checked;
if CheckBox1.Checked then begin
SrcList.Style:=lbOwnerDrawFixed;
SrcList.ItemHeight:=36
end else begin
SrcList.Style:=lbStandard;
SrcList.ItemHeight:=14;
end;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.DstListDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
if Source is TListbox then
if TListbox(Source).Name = 'SrcList' then
Accept:=true else Accept:=False;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.SrcListDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
if Source is TListbox then
if TListbox(Source).Name = 'DstList' then
Accept:=true else Accept:=False;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.SrcListMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ssShift in Shift then exit;
if Button = mbLeft then
with Sender as TListBox do
begin
if ItemAtPos(Point(X, Y), True) >= 0 then
BeginDrag(False);
end;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.DstListMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ssShift in Shift then exit;
if Button = mbLeft then
with Sender as TListBox do
begin
if ItemAtPos(Point(X, Y), True) >= 0 then
BeginDrag(False);
end;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.DstListDragDrop(Sender, Source: TObject; X,
Y: Integer);
var
Index: Integer;
begin
if Source is TListbox then
if TListbox(Source).Name = 'SrcList' then begin
Index := GetFirstSelection(SrcList);
MoveSelected(SrcList, DstList.Items);
SetItem(SrcList, Index);
end;
end;
{-----------------------------------------------------------------------}
procedure TIconListBoxDlg.SrcListDragDrop(Sender, Source: TObject; X,
Y: Integer);
var
Index: Integer;
begin
if Source is TListbox then
if TListbox(Source).Name = 'DstList' then begin
Index := GetFirstSelection(DstList);
MoveSelected(DstList, SrcList.Items);
SetItem(DstList, Index);
end;
end;
{-----------------------------------------------------------------------}
{-----------------------------------------------------------------------}
initialization
end.